package com.ziyun.erp.web.modules.goods.controller;

import java.text.SimpleDateFormat;
import java.util.*;

import com.ziyun.erp.common.utils.UserUtils;
import io.renren.common.validator.ValidatorUtils;
import org.apache.catalina.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.goods.entity.GoodsBrandEntity;
import com.ziyun.erp.modules.goods.service.GoodsBrandService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author
 * @email
 * @date 2018-08-20 09:57:04
 */
@RestController
@RequestMapping("goods/goodsbrand")
public class GoodsBrandController {
    @Autowired
    private GoodsBrandService goodsBrandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("goods:goodsbrand:list")
    public R list(@RequestParam Map<String, Object> params){
        params.put("sellerId",1);
        PageUtils page = goodsBrandService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    @RequiresPermissions("goods:goodsbrand:info")
    public R info(@PathVariable("brandId") Integer brandId){
        GoodsBrandEntity goodsBrand = goodsBrandService.selectById(brandId);
        return R.ok().put("goodsBrand", goodsBrand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("goods:goodsbrand:save")
    public R save(@RequestBody GoodsBrandEntity goodsBrand){
        goodsBrand.setCreateName(UserUtils.getCurentUser().getUsername());
        goodsBrand.setSellerId(1);
        goodsBrandService.insert(goodsBrand);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("goods:goodsbrand:update")
    public R update(@RequestBody GoodsBrandEntity goodsBrand){
        goodsBrand.setLastModify(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
        goodsBrandService.updateAllColumnById(goodsBrand);//全部更新
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("goods:goodsbrand:delete")
    public R delete(@RequestBody Integer[] brandIds){
        goodsBrandService.deleteBatchIds(Arrays.asList(brandIds));
        return R.ok();
    }

    /**
     * 全部品牌
     */
    @RequestMapping("/allList")
    public R allList(@RequestParam Map<String, Object> params){
//        PageUtils page = goodsBrandService.queryPage(params);
        HashMap<String, Object> map = new HashMap<>();
        map.put("disabled","false");
        map.put("seller_id",1);
        List<GoodsBrandEntity> brandEntityList = goodsBrandService.selectByMap(map);
        return R.ok().put("brandEntityList", brandEntityList);
    }

}
